

export namespace ContactType {
  export enum Value {
    联系人 = 'person',
    群聊 = 'chatroom',
    服务号 = 'gh',
    工具 = 'gj',
    OPENIM = "openim",
  }
  export const labels: Record<Value, string> = {
    [Value.联系人]: "联系人",
    [Value.群聊]: "群聊",
    [Value.服务号]: "服务号",
    [Value.工具]: "工具",
    [Value.OPENIM]: "OPENIM"
  };
  export const options = Object.keys(Value).map(k => ({ value: (Value as any)[k], label: k }));
  export function label(v: Value | undefined): string | undefined {
    if (!v) return void 0;
    return labels[v] ?? void 0;
  }
  export enum ToolUserName {
    PlaceholderFoldGroup = '@placeholder_foldgroup',
    FloatBottle = 'floatbottle',
    FMessage = 'fmessage',
    FileHelper = 'filehelper',
    QMessage = 'qmessage',
    WeiXin = 'weixin',
    NotifyMessage = 'notifymessage',
    NewsApp = 'newsapp',
    WeiboQQMail = 'weiboqqmail',
    LbsApp = 'lbsapp',
    QQFriend = 'qqfriend',
    TMessage = 'tmessage',
    QQSync = 'qqsync',
    ShakeApp = 'shakeapp',
    MediaNote = 'medianote',
    ReaderApp = 'readerapp',
    BlogApp = 'blogapp',
    FacebookApp = 'facebookapp',
    MasssendApp = 'masssendapp',
    MeishiApp = 'meishiapp',
    FeedsApp = 'feedsapp',
    Voip = 'voip',
    BlogAppWeixin = 'blogappweixin',
    BrandSessionHolder = 'brandsessionholder',
    WeixinReminder = 'weixinreminder',
    OfficialAccounts = 'officialaccounts',
    WXitil = 'wxitil',
    UserExperienceAlarm = 'userexperience_alarm',
    NotificationMessages = 'notification_messages',
    BrandServiceSessionHolder = 'brandservicesessionholder',
    MpHelper = 'mphelper',
  }
  export const ToolNickNames: Record<ToolUserName, string> = {
    [ToolUserName.PlaceholderFoldGroup]: "被折叠的群聊",
    [ToolUserName.FloatBottle]: ToolUserName.FloatBottle,
    [ToolUserName.FMessage]: "附近的人",
    [ToolUserName.FileHelper]: "文件传输助手",
    [ToolUserName.QMessage]: ToolUserName.QMessage,
    [ToolUserName.WeiXin]: "微信团队",
    [ToolUserName.NotifyMessage]: ToolUserName.NotifyMessage,
    [ToolUserName.NewsApp]: "腾讯新闻",
    [ToolUserName.WeiboQQMail]: "qq邮箱邮件提醒",
    [ToolUserName.LbsApp]: "地理位置服务",
    [ToolUserName.QQFriend]: "QQ好友离线消息",
    [ToolUserName.TMessage]: ToolUserName.TMessage,
    [ToolUserName.QQSync]: ToolUserName.QQSync,
    [ToolUserName.ShakeApp]: ToolUserName.ShakeApp,
    [ToolUserName.MediaNote]: ToolUserName.MediaNote,
    [ToolUserName.ReaderApp]: ToolUserName.ReaderApp,
    [ToolUserName.BlogApp]: ToolUserName.BlogApp,
    [ToolUserName.FacebookApp]: ToolUserName.FacebookApp,
    [ToolUserName.MasssendApp]: ToolUserName.MasssendApp,
    [ToolUserName.MeishiApp]: ToolUserName.MeishiApp,
    [ToolUserName.FeedsApp]: ToolUserName.FeedsApp,
    [ToolUserName.Voip]: ToolUserName.Voip,
    [ToolUserName.BlogAppWeixin]: ToolUserName.BlogAppWeixin,
    [ToolUserName.BrandSessionHolder]: ToolUserName.BrandSessionHolder,
    [ToolUserName.WeixinReminder]: ToolUserName.WeixinReminder,
    [ToolUserName.OfficialAccounts]: ToolUserName.OfficialAccounts,
    [ToolUserName.WXitil]: ToolUserName.WXitil,
    [ToolUserName.UserExperienceAlarm]: ToolUserName.UserExperienceAlarm,
    [ToolUserName.NotificationMessages]: ToolUserName.NotificationMessages,
    [ToolUserName.BrandServiceSessionHolder]: ToolUserName.BrandServiceSessionHolder,
    [ToolUserName.MpHelper]: ToolUserName.MpHelper
  }
  export function guess_contact_type(username: string): ContactType.Value {
    if (username in ToolNickNames) return ContactType.Value.工具;
    if (username.endsWith('@chatroom')) return ContactType.Value.群聊;
    if (username.endsWith("@openim")) return ContactType.Value.OPENIM;
    if (username.startsWith('gh_')) return ContactType.Value.服务号;
    return ContactType.Value.联系人;
  }
  export function is_username_met(username: string, contact_type: ContactType.Value | undefined): boolean {
    switch (contact_type) {
      case ContactType.Value.工具:
        return username in ToolNickNames
      case ContactType.Value.群聊:
        return username.endsWith('@chatroom')
      case ContactType.Value.OPENIM:
        return username.endsWith("@openim")
      case ContactType.Value.服务号:
        return username.startsWith('gh_');
      case ContactType.Value.联系人:
        return guess_contact_type(username) === ContactType.Value.联系人
    }
    return true
  }
}
